<%--
  Created by IntelliJ IDEA.
  User: gjd
  Date: 2023/2/3  15:44
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/style.css"/>
    <link href="assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/ace.min.css"/>
    <link rel="stylesheet" href="font/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="Widget/Validform/5.3.2/Validform.min.js"></script>
    <script src="assets/js/typeahead-bs2.min.js"></script>
    <script src="assets/js/jquery.dataTables.min.js"></script>
    <script src="assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="assets/layer/layer.js" type="text/javascript"></script>
    <script src="js/lrtk.js" type="text/javascript"></script>
    <script src="assets/layer/layer.js" type="text/javascript"></script>
    <script src="assets/laydate/laydate.js" type="text/javascript"></script>
    <title>管理员</title>
</head>

<body>
<div class="page-content clearfix">
    <div class="administrator">
        <div class="d_Confirm_Order_style">

            <!--管理员列表-->
            <div class="clearfix administrator_style" id="administrator">
                <div class="left_style">
                    <div id="scrollsidebar" class="left_Treeview">
                        <div class="show_btn" id="rightArrow"><span></span></div>
                        <div class="widget-box side_content">
                            <div class="side_title"><a title="隐藏" class="close_btn"><span></span></a></div>
                            <div class="side_list">
                                <div class="widget-header header-color-green2"><h4 class="lighter smaller">
                                    一级菜单列表</h4></div>
                                <div class="widget-body">
                                    <ul class="b_P_Sort_list">
                                        <li><i class="fa fa-users green"></i> <a href="getAllMenu">全部</a></li>

                                        <c:forEach items="${map.list1}" var="menu1">
                                            <li>
                                                <i class="fa fa-users orange"></i>
                                                <a href="javascript:void(0)"
                                                   onclick="getChildMenu('${menu1.menuCode}')">${menu1.menuName}</a>
                                            </li>
                                        </c:forEach>

                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="table_menu_list" id="testIframe">
                    <table class="table table-striped table-bordered table-hover" id="sample_table">
                        <thead>
                        <tr>
                            <th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label>
                            </th>
                            <th width="80px">菜单编码</th>
                            <th width="250px">菜单名称</th>
                            <th width="100px">菜单排序序号</th>
                            <th width="100px">菜单级别</th>
                            <th width="100px">父级菜单编码</th>
                            <th width="180px">请求url</th>
                            <th width="70px">状态</th>
                            <th width="200px">操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        <c:forEach items="${map.list2}" var="menu2">

                            <tr>
                                <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                                <td>${menu2.menuCode}</td>
                                <td>${menu2.menuName}</td>
                                <td>${menu2.menuOrder}</td>
                                <td>${menu2.menuLevel}</td>
                                <td>${menu2.parentMenuCode}</td>
                                <td>${menu2.menuUrl}</td>
                                <td class="td-status">
                                    <c:choose>
                                        <c:when test="${menu2.menuState=='1'}">
                                            <span class="label label-success radius">已启用</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="label label-defaunt radius">已停用</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>

                                <td class="td-manage">
                                    <c:choose>
                                        <c:when test="${menu2.menuState=='1'}">
                                            <a onclick="member_stop(this,${menu.menuId})" href="javascript:;"
                                               title="停用"
                                               class="btn btn-xs btn-success"><i
                                                    class="fa fa-check  bigger-120"></i></a>
                                        </c:when>
                                        <c:otherwise>
                                            <a style="text-decoration:none" class="btn btn-xs "
                                               onclick="member_start(this,${menu.menuId})" href="javascript:;"
                                               title="启用"><i
                                                    class="fa fa-close bigger-120"></i></a>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                            </tr>

                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    jQuery(function ($) {
        var oTable1 = $('#sample_table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable": false, "aTargets": [0, 2, 3, 4, 5, 7, 8,]}// 制定列不参与排序
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });


        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});

        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
            return 'left';
        }
    });

</script>
<script type="text/javascript">
    $(function () {
        $("#administrator").fix({
            float: 'left',
            //minStatue : true,
            skin: 'green',
            durationTime: false,
            spacingw: 50,//设置隐藏时的距离
            spacingh: 270,//设置显示时间距
        });
    });

    //字数限制
    function checkLength(which) {
        var maxChars = 100; //
        if (which.value.length > maxChars) {
            layer.open({
                icon: 2,
                title: '提示框',
                content: '您输入的字数超过限制!',
            });
            // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
            which.value = which.value.substring(0, maxChars);
            return false;
        } else {
            var curr = maxChars - which.value.length; //250 减去 当前输入的
            document.getElementById("sy").innerHTML = curr.toString();
            return true;
        }
    };
    //初始化宽度、高度
    $(".widget-box").height($(window).height() - 215);
    $(".table_menu_list").width($(window).width() - 260);
    $(".table_menu_list").height($(window).height() - 20);
    //当文档窗口发生改变时 触发
    $(window).resize(function () {
        $(".widget-box").height($(window).height() - 215);
        $(".table_menu_list").width($(window).width() - 260);
        $(".table_menu_list").height($(window).height() - 20);
    })
    laydate({
        elem: '#start',
        event: 'focus'
    });

    /*用户-停用*/
    function member_stop(obj, id) {
        $.ajax({
            url: "changeMenuState",
            data: {"menuId": id, "menuState": 0},
            success: function () {
                layer.confirm('确认要停用吗？', function (index) {
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onclick="member_start(this,' + id + ')" href="javascript:;" title="启用"><i class="fa fa-close bigger-120"></i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
                    $(obj).remove();
                    layer.msg('已停用!', {icon: 5, time: 1000});
                });
            }
        });
    }

    /*用户-启用*/
    function member_start(obj, id) {
        $.ajax({
            url: "changeMenuState",
            data: {"menuId": id, "menuState": 1},
            success: function () {
                layer.confirm('确认要启用吗？', function (index) {
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onclick="member_stop(this,' + id + ')" href="javascript:;" title="停用"><i class="fa fa-check  bigger-120"></i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                    $(obj).remove();
                    layer.msg('已启用!', {icon: 6, time: 1000});
                });
            }
        });


    }

    /*产品-编辑*/
    function member_edit(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }

    /*产品-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }


    //获取二级菜单
    function getChildMenu(code) {

        $.ajax({
            url: "getChildMenu",
            data: {"code": code},
            dataType: "json",
            success: function (result) {
                var html = "";
                for (var i = 0; i < result.length; i++) {
                    var menu = result[i];
                    var menuId = menu.menuId;
                    var menuCode = menu.menuCode;
                    var menuName = menu.menuName;
                    var menuOrder = menu.menuOrder;
                    var menuLevel = menu.menuLevel;
                    var parentMenuCode = menu.parentMenuCode;
                    var menuUrl = menu.menuUrl;
                    var menuState = menu.menuState;

                    html += "<tr>" +
                        '<td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>' +
                        "<td>" + menuCode + "</td>" +
                        "<td>" + menuName + "</td>" +
                        "<td>" + menuOrder + "</td>" +
                        "<td>" + menuLevel + "</td>" +
                        "<td>" + parentMenuCode + "</td>" +
                        " <td>" + menuUrl + "</td>";

                    if (menuState == 1) {
                        html += '<td class="td-status"><span class="label label-success radius">已启用</span></td>';
                    } else {
                        html += '<td class="td-status"><span class="label label-defaunt radius">已停用</span></td>';
                    }

                    if (menuState == 1) {
                        html += '<td class="td-manage"><a onclick="member_stop(this,' + menuId + ')"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a></td>';
                    } else {
                        html += '<td class="td-manage"><a onclick="member_start(this,' + menuId + ')" style="text-decoration:none" class="btn btn-xs "  href="javascript:;" title="启用"><i class="fa fa-close bigger-120"></i></a></td>';
                    }
                    html += "</tr>";
                }

                $('#sample_table').dataTable().fnDestroy();
                $("#sample_table tbody").html(html);
                $('#sample_table').dataTable({
                    bAutoWidth: false, //是否自动宽度
                });


            }
        });
    }
</script>



